package com.turing.procedure.utils;

import com.turing.common.entity.Context;
import com.turing.common.spring.SpringApplicationContext;
import com.turing.common.util.Tools;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description 自动任务上传场景工具类
 * @Author lcy
 * @Date 2021/8/16 10:04
 */
public class UploadUtil {

    /**
     * 上传名称
     */
    public static final Map<String,String> UPLOAD_NAME_MAP = new ConcurrentHashMap<>();

    /**
     * 部门名称集合
     */
    public static final List<String> UPLOAD_NAME_LIST = new ArrayList<>();

    static{
        UPLOAD_NAME_LIST.add("jjyyadmin");
        UPLOAD_NAME_LIST.add("yyfwadmin");
    }

    /**
     * 获取场景所属部门
     * @param templateId 场景id
     * @return java.lang.String
     * @author lcy
     * @date 2021/8/16 10:49
     **/
    public static String getUploadName(String templateId){
        //加载配置文件
        if (UPLOAD_NAME_MAP.isEmpty() || Tools.isEmpty(UPLOAD_NAME_MAP.get(templateId))) {
            //新股缴款公告、缴款通知书、追加提取、产品合同设置为基金运营部
            loadUploadName("upload.jjyyadmin","jjyyadmin");
            //银行理财、TA业务设置为运营服务部
            loadUploadName("upload.yyfwadmin","yyfwadmin");
        }

        //获取到值
        if (Tools.isNotEmpty(UPLOAD_NAME_MAP.get(templateId))) {
            return UPLOAD_NAME_MAP.get(templateId);
        } else {
            return Context.getTokenContext().getUserCode();
        }
    }

    /**
     * 加载配置文件内容
     * @author lcy
     * @date 2021/8/16 10:29
     **/
    private static void loadUploadName(String propertyName,String value){
        String property = SpringApplicationContext.getProperty(propertyName);
        String[] split = property.split(",");
        for (String templateId : split) {
            UPLOAD_NAME_MAP.put(templateId,value);
        }
    }

}
